home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / util / libs / chunky_dev.lha / chunky_dev / Demos / Drawing / Drawing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-17  |  3.9 KB  |  151 lines

  1. //
  2. // chunky.library demo
  3. //
  4. // This example shows how to do primitive drawing with chunky.library.
  5. //
  6. // (c) 1999 Rosande Limited, all rights reserved.
  7. // PUBLIC DOMAIN
  8. //
  9. // http://www.irrelevant.org/~oondy/chunky/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/libraries.h>
  13. #include <clib/chunky_protos.h>
  14. #include <libraries/chunky.h>
  15. #include <pragma/chunky_lib.h>
  16. #include <intuition/intuition.h>
  17. #include <pragma/intuition_lib.h>
  18. #include <pragma/graphics_lib.h>
  19. #include <pragma/exec_lib.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23.  
  24. #include "/_shared/screen.h"
  25. #include "/_shared/waitbutton.h"
  26. #include "/_shared/requester.h"
  27. #include "/_shared/text.h"
  28.  
  29. struct Library *ChunkyBase;
  30.  
  31. void DoDemo(void);
  32. BOOL DoDrawDemo(void);
  33.  
  34. main()
  35. {
  36.   if(ChunkyBase = OpenLibrary("chunky.library", 4))
  37.   {
  38.     if(DEMO_OpenScreen(640, 480, NULL, NULL))
  39.     {
  40.       CHK_ChooseHardwareMode(GetVPModeID(&DemoScreen->ViewPort));
  41.  
  42.       DoDemo();
  43.     }
  44.   }
  45.   else
  46.     printf("need chunky.library v4\n");
  47.  
  48.   if(DemoScreen) DEMO_CloseScreen();
  49.   if(ChunkyBase) CloseLibrary(ChunkyBase);
  50. }
  51.  
  52. void DoDemo(void)
  53. {
  54.   DEMO_Request("Right then.  Drawing, eh?\n\n"
  55.                "Here's a few lines, drawn on a 320x200 chunkyport.\n"
  56.                "This uses random colours and positions, but shows using\n"
  57.                "CHK_Move() and CHK_Draw() - like gfx.library's commands.",
  58.                "This library kicks ass", NULL);
  59.   if(!DoDrawDemo()) return;
  60.  
  61.   DEMO_Request("That concludes the drawing demo... how unexciting...", "Agreed", NULL);
  62. }
  63.  
  64. int randmax(int n) { int i; if(n < 1) return(0); for(;;) { i = rand(); if(!(i>n)) return(i); } }
  65.  
  66. BOOL DoDrawDemo(void)
  67. {
  68.   BOOL ok = FALSE;
  69.   struct ChunkyPort *cp = NULL;
  70.   int i, x, y, c, xx, yy;
  71.  
  72.   if(cp = CHK_InitChunky(320, 200))
  73.   {
  74.     DEMO_StatusText("Rendering 250 lines with CHK_Draw()...");
  75.  
  76.     for(i = 0; i < 250; i++)
  77.     {
  78.       c = randmax(256);
  79.       CHK_SetAPen(cp, c);
  80.  
  81.       x = randmax(320); y = randmax(200);
  82.       // Move to x,y
  83.       CHK_Move(cp, x, y);
  84.  
  85.       x = randmax(320-x); y = randmax(200-y);
  86.       // Draw to x,y
  87.       CHK_Draw(cp, x, y);
  88.     }
  89.  
  90.     DEMO_StatusText(NULL);
  91.     CHK_DrawChunky(cp, DemoWindow->RPort, (640-320)/2, (480-200)/2);
  92.  
  93.     DEMO_Request("Cool.. multi-coloured lines.\n\n"
  94.                  "Now for CHK_DrawRect()...", "Nice", NULL);
  95.  
  96.     CHK_ClearChunky(cp);
  97.  
  98.     DEMO_StatusText("Drawing 25 hollow and filled rectangles...");
  99.     for(i = 0; i < 25; i++)
  100.     {
  101.       // Draw a rectangle
  102.       c = randmax(256); CHK_SetAPen(cp, c);
  103.       x = randmax(320); y = randmax(200);
  104.       xx = x + randmax(320-x-1); yy = y + randmax(200-y-1);
  105.       CHK_DrawRect(cp, x, y, xx, yy);
  106.  
  107.       // Draw a filled rectangle
  108.       c = randmax(256); CHK_SetAPen(cp, c);
  109.       x = randmax(320); y = randmax(200);
  110.       xx = x + randmax(320-x-1); yy = y + randmax(200-y-1);
  111.       CHK_RectFill(cp, x, y, xx, yy);
  112.  
  113.       // Draw a "transparent" rectangle...
  114.       c = randmax(256); CHK_SetAPen(cp, c);
  115.       x = randmax(320); y = randmax(200);
  116.       xx = randmax(320-x-1); yy = randmax(200-y-1);
  117.       CHK_DrawTransparentRectangle(cp, x, y, xx, yy); //xx,yy = w,h
  118.     }
  119.  
  120.     DEMO_StatusText(NULL);
  121.     CHK_DrawChunky(cp, DemoWindow->RPort, (640-320)/2, (480-200)/2);
  122.  
  123.     DEMO_Request("Spunky boxes!\n\nCHK_DrawEllipse() time...", "Yeh!", NULL);
  124.  
  125.     CHK_ClearChunky(cp);
  126.  
  127.     DEMO_StatusText("Drawing 50 ellipses with CHK_DrawEllipse()...");
  128. #define MAX_RADX 25
  129. #define MAX_RADY 25
  130.     for(i = 0; i < 50; i++)
  131.     {
  132.       c = randmax(256); CHK_SetAPen(cp, c);
  133.       x = randmax(320-(MAX_RADX*2)); y = randmax(200-(MAX_RADY*2));
  134.       xx = randmax(MAX_RADX); yy = randmax(MAX_RADY);
  135.       // Draw an ellipse (xx,yy are radii not positions)
  136.       CHK_DrawEllipse(cp, x, y, xx, yy);
  137.     }
  138.  
  139.     DEMO_StatusText(NULL);
  140.     CHK_DrawChunky(cp, DemoWindow->RPort, (640-320)/2, (480-200)/2);
  141.  
  142.     DEMO_Request("Woo.. elliptical ellipses!", "Super", NULL);
  143.  
  144.     CHK_FreeChunky(cp); ok  = TRUE;
  145.   }
  146.   else
  147.    printf("no mem in DoDrawDemo()\n");
  148.  
  149.   return(ok);
  150. }
  151.